"""
题目：实现函数判断双链表是否为空（无任何节点）。
"""


class Node:
    def __init__(self, val=0, prev=None, next=None):
        self.val = val
        self.prev = prev  # 前驱节点
        self.next = next  # 后继节点

"""判断双链表是否为空"""
def is_empty(head):
    return head is None  # 头节点为None则为空


def create_doubly_linked_list(arr):
    """根据数组创建双链表"""
    if not arr:
        return None
    head = Node(arr[0])
    current = head
    for val in arr[1:]:
        new_node = Node(val)
        current.next = new_node  # 当前节点后继指向新节点
        new_node.prev = current  # 新节点前驱指向当前节点
        current = new_node
    return head


def traverse(head):
    """遍历双链表，返回值列表（正序）"""
    result = []
    current = head
    while current:
        result.append(current.val)
        current = current.next
    return result


# 测试
if __name__ == "__main__":
    empty_list = create_doubly_linked_list([])
    print(is_empty(empty_list))  # 输出: True

    non_empty_list = create_doubly_linked_list([1, 2, 3])
    print(is_empty(non_empty_list))  # 输出: False